// pages/latest/latest.js
var Api = require('../../utils/api.js');
Page({
  data: {
    title: '最新话题',
    latest: [],
    hidden: false
  },
  //下拉刷新
  onPullDownRefresh: function(){
    this.fetchData();
    console.log('onPullDownRefresh', new Date())
  },
  //跳转
  redictDetail: function(e){
    var id = e.currentTarget.id,
    url = '../detail/detail?id='+id;
    wx.navigateTo({
      url: url
    })
  },
  //加载数据
  fetchData: function(){
    var that = this;
    that.setData({
      hidden: false      
    });
    wx.request({
      url: Api.getLatestTopic({
        p: 1
      }),
      success: function(res){
        console.log(res);
        that.setData({
          latest: res.data
        });
        setTimeout(function(){
          that.setData({
            hidden: true
          });
        }, 1000);
      }      
    })
  },
  //加载时运行
  onLoad: function(){
    this.fetchData();
  }
})